import BaseCommand from "@/core/Frame/BaseClass/BaseCommand"

const PIE = window.PIE;
const EarthDraw = window.EarthDraw;

class AreaZoomInCommand extends BaseCommand {
  viewer: any
  globe: any
  draw: any
  
  constructor(params: any) {
    super();
    this.viewer = params.viewer;
    this.globe = params.viewer.getGlobe();
  }

  execute(option: any) {
    this.draw = new EarthDraw.setup(this.viewer, {});
    this.draw.changeMode('draw_dragRect');
    this.draw.on('draw.commit', (e: any) => {
      this.draw.clearFeatures()
      const bounds = e.feature.vertexs;
      const bound = new PIE.Bounds(bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]);
      this.globe.setViewBounds(bound);
      this.globe.refresh(false, false)
    })
  }

  release() {
    if (this.draw) {
      this.draw.changeMode('simple_select')
    }
  }

  isEnable(option: any) {
    return true
  }
}

export default AreaZoomInCommand